from flask_restful import Resource
import os
from flask import jsonify

# 获取当前文件的目录
BASE_DIR = os.path.dirname(os.path.abspath(__file__))

# 定义相对路径，并转换为绝对路径
UPLOAD_FOLDER = os.path.join(BASE_DIR, '../data')

# 确保目录存在
if not os.path.exists(UPLOAD_FOLDER):
    os.makedirs(UPLOAD_FOLDER)
class FileList(Resource):
    def get(self):
        finetune_path = os.path.join(UPLOAD_FOLDER, 'finetune_sets')
        question_path = os.path.join(UPLOAD_FOLDER, 'question_sets')

        # 获取文件列表并格式化
        finetune_files = [
            {"label": file, "value": file} for file in os.listdir(finetune_path)
        ]
        question_files = [
            {"label": file, "value": file} for file in os.listdir(question_path)
        ]

        return jsonify({
            "finetune_sets": finetune_files,
            "question_sets": question_files
        })


